package com.bo.baby2.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;

/**
 * @program: baby2_p2p
 * @description: 拦截器配置
 * @author:波
 * @create: 2020-07-13 16:52
 **/
@Configuration
public class InterceptorConfig2 implements WebMvcConfigurer {
    /**
     * 配置虚拟路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/avatar/**").addResourceLocations("file:D:\\y2\\baby2_p2p\\src\\main\\resources\\static\\avatar");
    }

    @Resource
    private InterceptorConfig interceptorConfig;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptorConfig).
                //设置拦截路径
                addPathPatterns("/**")
                //设置不拦截路径
                .excludePathPatterns("/login.html","/user/login","/user/register","/user/checkUsername","/index.html","/","/tpl-head.html"
                ,"/tpl-navbar.html","/finance/borrow/query","/tpl-footer.html","/register.html","/error","/logout")
                .excludePathPatterns("/admin/login.html")
                .excludePathPatterns("/css/**","/js/**","/images/**","/webjars/springfox-swagger-ui/**");
    }
}
